package com.wang.learn.common.builder;

import com.wang.learn.common.domain.Specification;
import lombok.RequiredArgsConstructor;

/**
 * @author : wcz
 * @version V1.0
 * @Description: 规则调用链构建器
 */
public class SpecificationChainBuilder<T> {

  private  Specification<T> base;

  public SpecificationChainBuilder(Specification<T> base){
    this.base = base;
  }

  public SpecificationChainBuilder<T> and(final Specification<T> other){
    Specification<T> old = base;
    this.base = new AndSpecification<T>(old,other);
    return this;
  }
  public SpecificationChainBuilder<T> or(final Specification<T> other){
    Specification<T> old = base;
    this.base = new OrSpecification<T>(old,other);
    return this;
  }
  public SpecificationChainBuilder<T> not(){
    Specification<T> old = base;
    this.base = new NotSpecification<T>(old);
    return this;
  }

  public Specification<T> build(){
    return base;
  }


}
